package com.ruoyi.web.controller.community.advert;

import java.util.List;

import com.ruoyi.community.domain.ChangeAdParams;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.AdPositionCommunity;
import com.ruoyi.community.service.IAdPositionCommunityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告位置Controller
 * 
 * @author hanning
 * @date 2022-04-30
 */
@RestController
@RequestMapping("/community/adposcomm")
public class AdPositionCommunityController extends BaseController
{
    @Autowired
    private IAdPositionCommunityService adPositionCommunityService;

    /**
     * 查询广告位置列表
     */
    @PreAuthorize("@ss.hasPermi('community:adposcomm:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdPositionCommunity adPositionCommunity)
    {
        startPage();
        List<AdPositionCommunity> list = adPositionCommunityService.selectAdPositionCommunityList(adPositionCommunity);
        return getDataTable(list);
    }

    /**
     *  根据社区id查询广告位置列表
     */
    @PreAuthorize("@ss.hasPermi('community:adposcomm:list')")
    @GetMapping("/list/community")
    public AjaxResult listByCommunity()
    {
        List<AdPositionCommunity> list = adPositionCommunityService.selectListByCid();
        return AjaxResult.success(list);
    }

    /**
     * 导出广告位置列表
     */
    @PreAuthorize("@ss.hasPermi('community:adposcomm:export')")
    @Log(title = "广告位置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AdPositionCommunity adPositionCommunity)
    {
        List<AdPositionCommunity> list = adPositionCommunityService.selectAdPositionCommunityList(adPositionCommunity);
        ExcelUtil<AdPositionCommunity> util = new ExcelUtil<AdPositionCommunity>(AdPositionCommunity.class);
        return util.exportExcel(list, "广告位置数据");
    }

    /**
     * 获取广告位置详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:adposcomm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(adPositionCommunityService.selectAdPositionCommunityById(id));
    }

    /**
     * 新增广告位置
     */
    @PreAuthorize("@ss.hasPermi('community:adposcomm:add')")
    @Log(title = "广告位置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdPositionCommunity adPositionCommunity)
    {
        return toAjax(adPositionCommunityService.insertAdPositionCommunity(adPositionCommunity));
    }

    /**
     * 修改广告位置
     */
    @PreAuthorize("@ss.hasPermi('community:adposcomm:edit')")
    @Log(title = "广告位置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdPositionCommunity adPositionCommunity)
    {
        return toAjax(adPositionCommunityService.updateAdPositionCommunity(adPositionCommunity));
    }

    @PreAuthorize("@ss.hasPermi('community:adposcomm:edit')")
    @Log(title = "更换广告", businessType = BusinessType.UPDATE)
    @PutMapping("/change")
    public AjaxResult change(@RequestBody ChangeAdParams params)
    {
        return toAjax(adPositionCommunityService.change(params));
    }

    /**
     * 删除广告位置
     */
    @PreAuthorize("@ss.hasPermi('community:adposcomm:remove')")
    @Log(title = "广告位置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(adPositionCommunityService.deleteAdPositionCommunityByIds(ids));
    }
}
